<template>
	<view class="content">
		<view class="background"></view>
		<view class="uni-list">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in news" :key="index"
@tap="openinfo" :data-newsid="item.post_id">
				<view class="uni-media-list">
					<image class="uni-media-list-logo" :src="item.author_avatar"></image>
					<view class="uni-media-list-body">
						<view class="uni-media-list-text-top">{{item.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis">{{item.created_at}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return{
				news : []
			};
		},
		onLoad: function(){
			uni.showLoading({
				title:"加载中..."
			});
			uni.request({
				url:'https://unidemo.dcloud.net.cn/api/news',
				method:'GET',
				data:{},
				success: res => {
					this.news = res.data;
					uni.hideLoading();
				},
				fail: () => {
					uni.hideLoading();
				}
			});
		},
		methods: {
			openinfo(e){
				var newsid = e.currentTarget.dataset.newsid;
				uni.navigateTo({
					url: '/pages/info/info?newsid=' + newsid
				});
			}
		}
	}
</script>

<style>
	

	.content {
	    padding: 20px; 
	    width: calc(100% - 40px); 
	    margin: auto; 
	    background-color: #e4ffff; 
	    border-radius: 8px; 
	    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
	    display: flex; 
	    flex-direction: column; 
	    align-items: center; 
	}

	.uni-list {
		position: relative;
		z-index: 1; 
	}

	.uni-list-cell {
		margin: 10px;
		border-radius: 12px;
		background-color: rgba(255, 255, 255, 0.9);
		transition: transform 0.2s ease, box-shadow 0.2s ease;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
	}
	.uni-list-cell:hover {
		transform: scale(1.02);
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
	}
	.uni-media-list {
		display: flex;
		padding: 12px;
	}
	.uni-media-list-logo {
		width: 50px;
		height: 50px;
		border-radius: 50%;
		margin-right: 12px;
	}
	.uni-media-list-body {
		height: auto;
		flex: 1;
	}
	.uni-media-list-text-top {
		font-weight: bold;
		font-size: 16px;
		line-height: 1.6em;
		color: #333;
	}
	.uni-media-list-text-bottom {
		color: #888;
		line-height: 1.4em;
	}
	.uni-ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>